package cn.melon.view.admin.library;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cn.melon.mod.library.LibraryBooksInfo;
import cn.melon.view.admin.library.ctr.AddbookCtr;

public class AddBookDig extends JDialog {
    /**
     * 
     */
//    private ActionListener listener = new LIbraryBookInfoCtr(this);
    
    private AddbookCtr listener = new AddbookCtr(this);
    
    private IUpdateBookTable updateBookTable = null;
    
    
    private static final long serialVersionUID = 1L;
    private JTextField bookID = new JTextField("",20);
    private JTextField bookName = new JTextField("",20);
    private JTextField publisher = new JTextField("",20);
    private JTextField author = new JTextField("",20);
    private JTextField loanable = new JTextField("",20);

    
    private JButton saveButton = new JButton("确定");
    private JButton cancelButton = new JButton("取消");
    String[] textStr = {"书籍编号：","书籍名称：","出版社：","作者：","可借数量："};
    
    JTextField[] jTextFields = {bookID,bookName,publisher,author,loanable};
    public AddBookDig() {
        initialize();
    }
    private void initialize(){
        this.setTitle("书籍信息");
        this.setSize(400, 300);
       
        JPanel panel = new JPanel();
        
        GridBagLayout layout = new GridBagLayout();

        panel.setLayout(layout);
        

        for(int i=0;i<textStr.length;i++){
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.anchor = GridBagConstraints.EAST;
            constraints.fill = GridBagConstraints.NONE;
            constraints.gridx = 0;
            constraints.gridy = i;
            constraints.weightx = 100;
            constraints.weighty = 100;
            panel.add(new JLabel(textStr[i]),constraints);
            constraints.anchor = GridBagConstraints.CENTER;
            constraints.gridx = 1;
            panel.add(jTextFields[i],constraints);
            constraints.anchor = GridBagConstraints.EAST;
            constraints.gridx = 2;
            panel.add(Box.createRigidArea(new Dimension(2, 15)));
        }
        
        JPanel tPanel = new JPanel();
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.anchor = GridBagConstraints.CENTER;
        constraints.fill = GridBagConstraints.NONE;
        constraints.gridx = 1;
        constraints.gridy = textStr.length;
        constraints.weightx = 100;
        constraints.weighty = 100;
        tPanel.add(saveButton);     //按钮
        tPanel.add(Box.createRigidArea(new Dimension(10, 15)));
        tPanel.add(cancelButton);
        panel.add(tPanel,constraints);      //按钮
        
        this.add(panel);
        this.setResizable(false);
        saveButton.addActionListener(listener);
        cancelButton.addActionListener(listener);
    }
    
    public LibraryBooksInfo getBook(){
        LibraryBooksInfo booksInfo = new LibraryBooksInfo();
        booksInfo.setBookID(bookID.getText());
        booksInfo.setBookName(bookName.getText());
        booksInfo.setAuthor(author.getText());
        booksInfo.setPublisher(publisher.getText());
        booksInfo.setLoanable(loanable.getText());
        booksInfo.setBorrowDate("");
        booksInfo.setBorrowStudent("");
        booksInfo.setDDL("");
        booksInfo.setReturnDate("");
        return booksInfo;
    }
}
